package com.kudian.restful.service;

import com.kudian.common.persistence.HibernateDao;
import com.kudian.common.service.BaseService;
import com.kudian.restful.dao.AdDao;
import com.kudian.restful.dao.LayoutDao;
import com.kudian.restful.dao.MediaResDao;
import com.kudian.restful.dao.WelInfoDao;
import com.kudian.restful.entity.Ad;
import com.kudian.restful.entity.AppVersion;
import com.kudian.restful.entity.WelInfo;
import com.kudian.restful.vo.welinfo.WelInfoPageRetVO;
import org.apache.log4j.Logger;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2016/4/18.
 */
@Service
@Transactional(readOnly = true)
public class WelInfoService extends BaseService<WelInfo, Integer> {
    private static final Logger logger = Logger.getLogger(WelInfoService.class);

    @Autowired
    private WelInfoDao welInfoDao;

    @Autowired
    private MediaResService mediaResService;

    @Override
    public HibernateDao<WelInfo, Integer> getEntityDao() {
        return welInfoDao;
    }

    public WelInfoPageRetVO welcomepage() {
        List<WelInfo> wis = welInfoDao.findbyorder("addTime", false);
        WelInfoPageRetVO retVO = new WelInfoPageRetVO();

        if (wis == null || wis.isEmpty()) {
            retVO.setPicuri("");
            return retVO;
        }
        WelInfo wi = wis.get(0);
        retVO.setPicuri(mediaResService.getResUrl(wi.getMediaId()));
        return retVO;
    }
}
